import Cookies from 'js-cookie'
import _ from 'lodash'

const Cookie = Cookies.withConverter({
  write: (value, name) => value
})

export function setZhiPinToken(cookiestring: string) {
  cookiestring.split(';').forEach((cookieItem: string) => {
    if (_.trim(cookieItem)) {
      const [key, value] = cookieItem.split('=')
      if (_.trim(key) && _.trim(value)) {
        Cookie.set(key.trim(), value.trim())
      }
    }
  })
}

export function removeAllCookies() {
  document.cookie.split(/; ?/).forEach(function (cookie) {
    Cookies.remove(cookie.split('=')[0])
  })
}

export default Cookie
